package seismosurfer.domain;

import java.io.IOException;
import java.io.PrintWriter;

import com.Ostermiller.util.CSVPrint;
import com.Ostermiller.util.CSVPrinter;

/**
 * Exports data in the CSV file format.
 *
 */
public class CSVExport extends Export {

    public static final String CSV_SUFFIX = "csv";

    public CSVExport() {
    }

    public String getExtension() {
        return CSV_SUFFIX;
    }

    public String getDescription() {
        return "CSV (Comma delimited)";
    }

    public void doExport(PrintWriter out) throws IOException {
        CSVPrint p = getPrinter(out);
        p.println(getQuakeData());
        p.close();
    }
    
    /**
     * A factory method that instantiates the
     * appropriate CSVPrint subclass, that
     * performs the actual output in the desired 
     * format.
     * 
     * @param out the output stream where the data 
     *        are written
     * @return a CSVPrint subclass object
     */
    protected CSVPrint getPrinter(PrintWriter out) {
        return new CSVPrinter(out);
    }

}
